home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / Libraries / ABox 1.9.5 / CPlus Files / ABText.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-10-26  |  12.0 KB  |  526 lines  |  [TEXT/MMCC]

  1. /*    
  2.     Copyright © 1991-1995 by TopSoft Inc.  All rights reserved.
  3.  
  4.     You may distribute this file under the terms of the TopSoft
  5.     Artistic License, accompanying this package.
  6.     
  7.     This file was developed by George (ty) Tempel in connection with TopSoft, Inc..
  8.     See the Modification History for more details.
  9.  
  10. Product
  11.     About Box
  12.  
  13. FILE
  14.     ABText.c
  15.  
  16. NAME
  17.     ABText.c, part of the ABox project source code,
  18.     responsible for handling the AboutBox Text class stuff.
  19.  
  20. DESCRIPTION
  21.     This file contains defines for the about box modules.
  22.     
  23. DEVELOPED BY
  24.     George (ty) Tempel                ttempel@monmouth.com
  25.     All code in this file, and its associated header file was
  26.     Created by George (ty) Tempel in connection with the TopSoft, Inc.
  27.     "FilterTop" application development, except where noted.
  28.  
  29. CARETAKER - George (ty) Tempel <ttempel@monmouth.com>
  30.      Please consult this person for any changes or suggestions to this file.
  31.  
  32. MODIFICATION HISTORY
  33.  
  34.     dd mmm yy    -    xxx    -    patchxx: description of patch
  35.     9 June 94    -    ty    -    Initial Version Created
  36.     20-july-94    -    ty    -    initial version released
  37.     28-july-94    -    ty    -    1.0.6--additions to support settable drag mgr usage
  38.                                     via the ABox Get/SetProperty methods
  39.     26-apr-95    -    ty    -    1.0.7--small fixes to tighten up scrolling vs drag handling
  40.     23-may-95    -    ty    -    changes for compatibility with the CodeWarrior CW6
  41.                             release and the associated Universal Headers from Apple:
  42.                             most methods that returned references now have "Ref" at
  43.                             the end of their methods names to prevent possible collisions
  44.                             with datatypes and classes of the same name (older versions
  45.                             of the compiler didn't have a problem with this).
  46.     25-oct-95    -    ty    -    changes for "const" usage under CW7; simplification of Boolean
  47.                             query methods
  48. */
  49.  
  50. /*===========================================================================*/
  51.  
  52. /*======= Segmentation directives ========*/
  53.  
  54. #ifdef USE_MANUAL_SEGMENTATION
  55. #pragma segment ty
  56. #endif
  57.  
  58. /*============ Header files ==============*/
  59.     
  60. #include     "ABText.h"
  61. #include    "ABox.h"
  62.  
  63. /*=============== Globals ================*/
  64.  
  65. /*================ CODE ==================*/
  66.  
  67.  
  68. /*=============================== ABText::ABText ================================*/
  69. ABText::ABText(void)
  70. {
  71.     //visibleObject = true;
  72.     mTEh = NULL;
  73.     mScrollH = NULL;
  74.     mResType = kABtextResource;
  75. } // end ABText
  76.  
  77.  
  78.  
  79.  
  80. /*=============================== ABText::~ABText ================================*/
  81. ABText::~ABText(void)
  82. {
  83.     if (this->HasTEh())
  84.     {
  85.         ::TEDispose (this->TEh());
  86.         this->TEh() = NULL;
  87.     }
  88.     
  89.     if (this->HasScrollbar())
  90.     {
  91.         ::DisposeControl(this->Scrollbar());
  92.         this->Scrollbar() = NULL;
  93.     } 
  94.         
  95. } // end ~ABText
  96.  
  97.  
  98.  
  99.  
  100.  
  101. /*=============================== ABText::Draw ================================*/
  102. OSErr    ABText::Draw(WindowPtr window)
  103. {
  104.     OSErr                error = noErr;
  105.     //    begin here...
  106.     
  107.     error = ABObject::Draw(window);
  108.  
  109.     if (error == noErr)
  110.         error = this->InitializeResource();
  111.  
  112.     this->ObjectRect().right -= kABscrollBarWidth;
  113.     
  114.     if (error == noErr)
  115.     {
  116.         Rect box;
  117.         long teHeight;
  118.         long firstLine = 0;
  119.         
  120.         box = this->ObjectRect();
  121.  
  122.         if (!this->HasTEh())
  123.         {
  124.             error = this->BuildText(&box, this->OurWindowRef());
  125.             if (!this->HasTEh())
  126.             {
  127.                 //    TENew failed, so let's just do a simple NeoTextBox here...
  128.                 //
  129.                 //    now move the right side back out because
  130.                 //    we won't use a scroll bar
  131.                 box.right -= kABscrollBarWidth;
  132.                 ::HLockHi (this->ResourceHandleRef());
  133.                 error = this->DrawTextBox (
  134.                         (unsigned char *)&(this->ResourceHandleRef())[1],    //    unsigned char *c
  135.                         **(this->ResourceHandleRef()),                    //    unsigned long textSize
  136.                         &box,                            //    Rect *displayWrapRect
  137.                         teJustCenter,                     //    short alignmentConstants
  138.                         0,                                //    lineHeightCode (0 = default)
  139.                         NULL,                            //    short *endY baseline
  140.                         NULL);                            //    short *lineHeight
  141.                 ::HUnlock (this->ResourceHandleRef());
  142.                 
  143.                 this->ObjectRect().right += kABscrollBarWidth;
  144.                 return error;
  145.             } // end if else block
  146.         
  147.         } else {
  148.         
  149.             ::TEUpdate (&box, this->TEh());
  150.         } // end if else block
  151.         
  152.         //    the scroll bar _might_ be needed, so determine just
  153.         //    how tall the text is on the screen, and how tall could
  154.         //    it be (potential height, if all text were being displayed)
  155.         //
  156.         ::HLockHi (this->ResourceHandleRef());
  157.         teHeight = ::TEGetHeight ((*(this->TEh()))->nLines, firstLine, this->TEh());
  158.         ::HUnlock (this->ResourceHandleRef());
  159.     
  160.         if (teHeight >= (box.bottom - box.top)) 
  161.         {
  162.             if (!this->HasScrollbar())
  163.             {
  164.                 //    need the scroll bar...
  165.                 Rect scrollbarRect;
  166.                 
  167.                 scrollbarRect.top = box.top - 1;
  168.                 scrollbarRect.bottom = box.bottom + 1;
  169.                 scrollbarRect.left = box.right + 1;
  170.                 scrollbarRect.right = scrollbarRect.left + kABscrollBarWidth;
  171.                 
  172.                 this->Scrollbar() = ::NewControl (this->GetWindow(),        //    the window
  173.                                                     &scrollbarRect,            //    the rect
  174.                                                     "\pVScroll",            //    the title
  175.                                                     true,                    //    visible
  176.                                                     1,                        //    initial value
  177.                                                     1,                        //    minimum value
  178.                                                     teHeight,                //    maximum value
  179.                                                     scrollBarProc,            //    control is a scrollbar
  180.                                                     (long)(this->TEh()));    //    the reference constant
  181.                                                     
  182.                 error = ::ResError();
  183.  
  184.             }    //    end if (scrollH) block
  185.             
  186.             if (this->HasScrollbar())
  187.             {
  188.                 //    make it visible
  189.                 ::ShowControl (this->Scrollbar());
  190.                 ::HiliteControl (this->Scrollbar(), kActivateControl);
  191.                 
  192.                 this->FixScrollBar (this->Scrollbar());
  193.             } // end if else block...
  194.             
  195.         }    //    end if else block...
  196.     
  197.     }
  198.  
  199.     this->ObjectRect().right += kABscrollBarWidth;
  200.     
  201.     return error;
  202.     
  203. } // end Draw
  204.  
  205.  
  206.  
  207.  
  208. /*=============================== ABText::BuildText ================================*/
  209. OSErr    ABText::BuildText(Rect* area, WindowPtr /*window*/)
  210. {
  211.     OSErr                error = noErr;
  212.     
  213.     StScrpHandle        styleHandle = NULL;
  214.     
  215.     Rect                box;
  216.     
  217.     long                textLen = 0;
  218.     
  219.     //    begin here...
  220.     
  221.     if (area)
  222.         box = *area;
  223.     else
  224.         box = this->ObjectRect();
  225.     
  226.     //    see if we can find out a little more on the text resource...if it has
  227.     //    a corresponding 'styl' resource.
  228.     
  229.     //    we have the information, so now try to load a style 'styl' resource
  230.     //    and use it for the text.
  231.     styleHandle = (StScrpHandle)::Get1Resource (kABStyleResource, this->ResID());
  232.     error = ::ResError();
  233.     if (error) 
  234.     {
  235.         //    something's amiss...
  236.         this->TEh() = ::TENew (&box, &box);
  237.         styleHandle = NULL;
  238.         error = noErr;
  239.     } else {
  240.         //    nope, no problems, we have a TEXT and a styl resource,
  241.         //    so create a stylized text record
  242.         this->TEh() = ::TEStylNew (&box, &box);
  243.     }    //    end if block...
  244.  
  245.     if (!this->HasTEh())
  246.     {
  247.         error = paramErr;
  248.     } else {
  249.         
  250.         //    insert the text into the TEHandle
  251.         //
  252.         textLen = ::GetHandleSize (this->ResourceHandleRef());
  253.         ::HLockHi (this->ResourceHandleRef());
  254.         if (styleHandle) 
  255.         {
  256.             TEActivate (this->TEh());
  257.             TEStylInsert(*(this->ResourceHandleRef()), textLen, styleHandle, this->TEh());
  258.             TEDeactivate (this->TEh());
  259.         
  260.         } else {
  261.             TEInsert(*(this->ResourceHandleRef()), textLen, this->TEh());
  262.         }    // end if (styleHandle) block
  263.         ::HUnlock(this->ResourceHandleRef());
  264.         
  265.         //    release the style resource that shadows the text
  266.         if (styleHandle) 
  267.         {
  268.             ::ReleaseResource((Handle)styleHandle);
  269.         }    //    end if block
  270.             
  271.     }
  272.     
  273.     return error;
  274. } // end BuildText
  275.  
  276.  
  277.  
  278.  
  279.  
  280. /*=============================== ABText::Update ================================*/
  281. OSErr    ABText::Update(WindowPtr window)
  282. {
  283.  
  284.     OSErr    error = noErr;
  285.     
  286.     //    begin here...
  287.     //
  288.     //    Draw a bezel around the field _including_ the scroll bar
  289.     //
  290.     //error = ABObject::Update(window);
  291.     this->OurWindowRef() = window;
  292.     error = this->DrawFrame();
  293.     if (this->HasTEh() && (error == noErr))
  294.     {
  295.         Rect box = this->ObjectRect();
  296.         ::TEUpdate (&box, this->TEh());
  297.     } // end if block
  298.     
  299.     return error;
  300.     
  301. } // end Update
  302.  
  303.  
  304.  
  305.  
  306.  
  307. /*=============================== ABText::Event ================================*/
  308. Boolean    ABText::Event(EventRecord *event)
  309. {
  310.     Boolean        handled = false;
  311.     Point        where;
  312.     OSErr        error = noErr;
  313.     Rect        scrollBarRect;
  314.     Rect        box = this->ObjectRect();
  315.     
  316.     //    begin here...
  317.     //
  318.     if (!event || this->DoesntHaveWindow())
  319.         return false;
  320.         
  321.     switch (event->what) 
  322.     {
  323.         case    mouseDown:
  324.             //    1.0.6 ty--check to see if we're allowed to use the DragMgr
  325.             //
  326.             ABox *theABox = (ABox *)::GetWRefCon (this->OurWindowRef());
  327.             Boolean    useDrag = false;
  328.             
  329.             if (theABox)
  330.                 error = theABox->GetProperty(kABoxUseDragMgr, &useDrag, NULL);
  331.                 
  332.             where = event->where;
  333.             ::GlobalToLocal(&where);
  334.             if (::FrontWindow() != this->OurWindowRef())
  335.                 break;
  336.                 
  337.             if (this->HasScrollbar()) 
  338.             {
  339.                 scrollBarRect = (*(this->Scrollbar()))->contrlRect;
  340.                 if (::PtInRect(where, &scrollBarRect))
  341.                 {
  342.                     this->ScrollBarClick( this->Scrollbar(), where );
  343.                     this->FixScrollBar (this->Scrollbar());
  344.                     handled = true;
  345.                 } // end if block
  346.             }
  347.             
  348.             if (::PtInRect (where, &box) && ABUEnvDragMgr::IsPresent() && useDrag && !handled) {
  349.                 //    DragMgr stuff here!!!
  350.                 
  351.                 if (::WaitMouseMoved(event->where)) 
  352.                 {
  353.                     //    the user is trying to Drag
  354.                     //    from the field to someplace
  355.                     this->DragMgrEventRef() = event;
  356.                     error = this->Begin();
  357.                     error = this->End();
  358.                 } // end if block
  359.             } // end if block
  360.             break;
  361.         default:
  362.             break;
  363.     } // end switch block
  364.     
  365.     return handled;
  366. } // end Event
  367.  
  368.  
  369.  
  370.  
  371. /*=============================== ABText::Stop ================================*/
  372. OSErr    ABText::Stop(void)
  373. {
  374.     OSErr    error = noErr;
  375.     
  376.     //    begin here...
  377.     //
  378.     if (this->HasScrollbar())
  379.     {
  380.         ::DisposeControl (this->Scrollbar());
  381.         this->Scrollbar() = NULL;
  382.     } // end if block
  383.     
  384.     error = kABTextSuperProperties::Stop();
  385.     return error;
  386.     
  387. } // end Stop
  388.  
  389.  
  390.  
  391.  
  392.  
  393. /*=============================== ABText::Initialize ================================*/
  394. OSErr    ABText::Initialize(void)
  395. {
  396.     OSErr                error = noErr;
  397.     Ptr                    ptr = NULL;
  398.     Size                ptrSize = 0;
  399.     StScrpHandle        theStyle;
  400.     
  401.     //    OVERRIDE of the ABUEnvDragMgr method!
  402.     if (this->IsDragInitialized())
  403.         return noErr;
  404.     
  405.     this->DragRectRef() = this->ObjectRect();
  406.     error = ABUEnvDragMgr::Initialize();
  407.     if (error)
  408.         return error;
  409.         
  410.     error = ::SetDragSendProc (this->DragRef(),
  411.                             this->DragUPPRef(),
  412.                             this);
  413.     if (error)
  414.         return error;
  415.     
  416.     //    now create the Send information
  417.     ::HLock (this->ResourceHandleRef());
  418.     ptr = (Ptr)*(this->ResourceHandleRef());
  419.     ptrSize = ::GetHandleSize(this->ResourceHandleRef());
  420.     error = ::AddDragItemFlavor(this->DragRef(),
  421.                                 this->ItemRef(),
  422.                                 kABtextResource,
  423.                                 ptr,
  424.                                 ptrSize,
  425.                                 kABdefaultFlavorFlags);
  426.     ::HUnlock (this->ResourceHandleRef());
  427.     
  428.     //    now add the 2nd flavor, the style stuff
  429.     theStyle = ::GetStylScrap(this->TEh());
  430.     ::HLock((Handle) theStyle);
  431.     ptr = (Ptr)*theStyle;
  432.     ptrSize = ::GetHandleSize((Handle)theStyle);
  433.     error = ::AddDragItemFlavor(this->DragRef(),
  434.                                 this->ItemRef(), 
  435.                                 kABstyleResource, 
  436.                                 ptr, 
  437.                                 ptrSize,
  438.                                 kABdefaultFlavorFlags);
  439.     ::HUnlock((Handle) theStyle);
  440.     ::DisposeHandle((Handle) theStyle);
  441.  
  442.  
  443.     this->DragInitializedRef() = true;    
  444.     
  445.     return error;
  446.  
  447. }    // end Initialize
  448.  
  449.  
  450.  
  451.  
  452.  
  453. /*=============================== ABText::Begin ================================*/
  454. OSErr    ABText::Begin(void)
  455. {
  456.     OSErr    error;
  457.     
  458.     //    OVERRIDE of the ABUEnvDragMgr method! but be certain to call
  459.     //    the ABUEnvDragMgr method when finished here!!!!
  460.     
  461.     error = this->Initialize();
  462.     if (error)
  463.         return error;
  464.         
  465.     error = ABUEnvDragMgr::Begin();
  466.     
  467.     return error;
  468.  
  469. }    // end Begin
  470.  
  471.  
  472.  
  473.  
  474.  
  475. /*=============================== ABText::LocalSendProc ================================*/
  476. //
  477. OSErr    ABText::LocalSendProc(FlavorType theType,
  478.                                     void* /*dragSendRefCon*/,
  479.                                     ItemReference theItemRef,
  480.                                     DragReference theDragRef)
  481. {
  482.     OSErr                error = noErr;
  483.     Ptr                    ptr = NULL;
  484.     Size                ptrSize = 0;
  485.     StScrpHandle        theStyle;
  486.  
  487.     //    begin here...
  488.     
  489.     if (theType == kABstyleResource) 
  490.     {
  491.  
  492.         theStyle = ::GetStylScrap(this->TEh());
  493.  
  494.         //
  495.         //    Call SetDragItemFlavorData to provide the requested data.
  496.         //
  497.  
  498.         ::HLock((Handle) theStyle);
  499.         ptr = (Ptr)*theStyle;
  500.         ptrSize = ::GetHandleSize((Handle)theStyle);
  501.         error = ::SetDragItemFlavorData(theDragRef, 
  502.                                 theItemRef, 
  503.                                 kABstyleResource, 
  504.                                 ptr,
  505.                                 ptrSize,
  506.                                 kABdefaultFlavorFlags);
  507.         ::HUnlock((Handle) theStyle);
  508.         ::DisposeHandle((Handle) theStyle);
  509.  
  510.     } else {
  511.  
  512.         return badDragFlavorErr;
  513.  
  514.     }
  515.  
  516.     return error;
  517.  
  518. } // end LocalSendProc()
  519.  
  520.  
  521.  
  522.  
  523.  
  524. //    end of file
  525.  
  526.